package com.web.controller.dormManagement;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.common.apiresult.CommonResult;
import com.common.domain.dto.StudentDormQueryDTO;
import com.service.serviceInterface.StudentDormService;
import com.service.utils.SecurityUtil;
import com.system.entity.StudentDorm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author liuxuhuang
 * @date 2023年04月04日 11:26
 * @desc 学生住宿信息控制器
 */
@RestController
@Api(value = "studentDorm", tags = "学生住宿信息控制器")
@RequestMapping(value = "/dormManagement/studentDorm")
@Slf4j
public class StudentDormController {
    @Resource
    private SecurityUtil securityUtil;
    @Resource
    private StudentDormService studentDormService;

    @GetMapping
    @ApiOperation(value = "获取所在楼宇学生信息")
    public CommonResult get(StudentDormQueryDTO dto) {
        long userId = securityUtil.getUserId(SecurityContextHolder.getContext());
        return studentDormService.getData(dto, userId);
    }

    @DeleteMapping
    @ApiOperation(value = "删除所在楼宇宿舍财产信息（批量）")
    public CommonResult delete(@RequestParam("ids") String ids) {
        if (ids.contains(",")) {
            String[] split = ids.split(",");
            List<String> strings = Arrays.asList(split);
            return studentDormService.remove(new LambdaQueryWrapper<StudentDorm>().in(StudentDorm::getStudentId, strings)) ? CommonResult.success() : CommonResult.failed();
        }
        return studentDormService.remove(new LambdaQueryWrapper<StudentDorm>().in(StudentDorm::getStudentId, ids)) ? CommonResult.success() : CommonResult.failed();
    }

    @PutMapping
    @ApiOperation(value = "修改所在楼宇学生信息")
    public CommonResult update() {
        return CommonResult.success();
    }

}
